//
//  WHBankInfoView.m
//  SquirrelSeller
//
//  Created by 邓伟浩 on 2019/1/14.
//  Copyright © 2019 邓伟浩. All rights reserved.
//

#import "WHBankInfoView.h"
#import "WHBankNameHelper.h"

@interface WHBankInfoView ()

//@property (nonatomic, strong) UIView *infoContentView;
@property (nonatomic, strong) UIImageView *infoContentView;
@property (nonatomic, strong) UILabel *bankDesLabel;

@property (nonatomic, strong) UIView *gapView;

@property (nonatomic, strong) UILabel *userNameTipsLabel;
@property (nonatomic, strong) UILabel *bankNameTipsLabel;
@property (nonatomic, strong) UILabel *cardNumberTipsLabel;

@property (nonatomic, strong) UILabel *userNameLabel; // 持卡人姓名
@property (nonatomic, strong) UILabel *bankNameLabel; // 开户银行
@property (nonatomic, strong) UILabel *cardNumberLabel; // 银行卡卡号

@end

@implementation WHBankInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpBankInfoUI];
    }
    return self;
}

- (void)setUpBankInfoUI {
    [self addSubview:({
        _infoContentView = [[UIImageView alloc] init];
        _infoContentView.contentMode = UIViewContentModeScaleAspectFill;
        _infoContentView.image = IMAGE_NAMED(@"bank_back");
//        _infoContentView = [[UIView alloc] init];
//        _infoContentView.backgroundColor = CMDarkOrangeColor;
//
//        _infoContentView.layer.cornerRadius  = 12;
//        _infoContentView.layer.masksToBounds = NO;
//
//        _infoContentView.layer.shadowColor = HexColor(@"002233").CGColor;
//        _infoContentView.layer.shadowOffset = CGSizeMake(0, 0);
//        _infoContentView.layer.shadowOpacity = 0.1;
//        _infoContentView.layer.shadowRadius = 5;
        
        _infoContentView;
    })];
    
    [_infoContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top).offset(kRealwidth(15));
        make.left.mas_equalTo(self.mas_left).offset(kRealwidth(15));
        make.right.mas_equalTo(self.mas_right).offset(-kRealwidth(15));
        make.bottom.mas_equalTo(self.mas_bottom).offset(-kRealwidth(15));
    }];
    
    [_infoContentView addSubview:({
        _bankDesLabel = [[UILabel alloc] init];
        _bankDesLabel.textColor = KWhiteColor;
        _bankDesLabel.text = @"";
        _bankDesLabel.font = SYSTEMFONT(kRealwidth(15));
        _bankDesLabel.adjustsFontSizeToFitWidth = YES;
        _bankDesLabel.textAlignment = NSTextAlignmentCenter;
        _bankDesLabel;
    })];
    [_bankDesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_infoContentView.mas_centerX);
        make.height.mas_equalTo(kRealwidth(15));
        make.top.mas_equalTo(_infoContentView.mas_top).offset(kRealwidth(15));
        make.width.mas_equalTo(_infoContentView.mas_width);
    }];
    
    [_infoContentView addSubview:({
        _gapView = [[UIView alloc] init];
        _gapView.backgroundColor = CLineColor;
        _gapView;
    })];
    [_gapView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_infoContentView.mas_left).offset(kRealwidth(30));
        make.right.mas_equalTo(_infoContentView.mas_right).offset(-kRealwidth(30));
        make.height.mas_equalTo(0.5);
        make.top.mas_equalTo(_bankDesLabel.mas_bottom).offset(kRealwidth(15));
    }];
    
    [_infoContentView addSubview:({
        _userNameTipsLabel = [[UILabel alloc] init];
        _userNameTipsLabel.text = @"持卡人姓名";
        _userNameTipsLabel.textColor = KWhiteColor;
        _userNameTipsLabel.font = SYSTEMFONT(kRealwidth(17));
        _userNameTipsLabel.textAlignment = NSTextAlignmentRight;
        _userNameTipsLabel;
    })];
    [_userNameTipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_infoContentView.mas_left).offset(kRealwidth(30));
        make.top.mas_equalTo(_gapView.mas_bottom).offset(kRealwidth(25));
        make.width.mas_equalTo(kRealwidth(100));
        make.height.mas_equalTo(kRealwidth(17));
    }];
    
    [_infoContentView addSubview:({
        _bankNameTipsLabel = [[UILabel alloc] init];
        _bankNameTipsLabel.text = @"开户银行";
        _bankNameTipsLabel.textColor = KWhiteColor;
        _bankNameTipsLabel.font = SYSTEMFONT(kRealwidth(17));
        _bankNameTipsLabel.textAlignment = NSTextAlignmentRight;
        _bankNameTipsLabel;
    })];
    [_bankNameTipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_infoContentView.mas_left).offset(kRealwidth(30));
        make.top.mas_equalTo(_userNameTipsLabel.mas_bottom).offset(kRealwidth(15));
        make.width.mas_equalTo(kRealwidth(100));
        make.height.mas_equalTo(kRealwidth(17));
    }];
    
    [_infoContentView addSubview:({
        _cardNumberTipsLabel = [[UILabel alloc] init];
        _cardNumberTipsLabel.text = @"银行卡卡号";
        _cardNumberTipsLabel.textColor = KWhiteColor;
        _cardNumberTipsLabel.font = SYSTEMFONT(kRealwidth(17));
        _cardNumberTipsLabel.textAlignment = NSTextAlignmentRight;
        _cardNumberTipsLabel;
    })];
    [_cardNumberTipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_infoContentView.mas_left).offset(kRealwidth(30));
        make.top.mas_equalTo(_bankNameTipsLabel.mas_bottom).offset(kRealwidth(15));
        make.width.mas_equalTo(kRealwidth(100));
        make.height.mas_equalTo(kRealwidth(17));
    }];
    
    [_infoContentView addSubview:({
        _userNameLabel = [[UILabel alloc] init];
        _userNameLabel.text = @"";
        _userNameLabel.textColor = KWhiteColor;
        _userNameLabel.font = SYSTEMFONT(kRealwidth(17));
        _userNameLabel.textAlignment = NSTextAlignmentLeft;
        _userNameLabel;
    })];
    [_userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_userNameTipsLabel.mas_right).offset(kRealwidth(35));
        make.top.mas_equalTo(_userNameTipsLabel.mas_top);
        make.right.mas_equalTo(_infoContentView.mas_right).offset(kRealwidth(30));
        make.height.mas_equalTo(kRealwidth(17));
    }];
    
    [_infoContentView addSubview:({
        _bankNameLabel = [[UILabel alloc] init];
        _bankNameLabel.text = @"";
        _bankNameLabel.textColor = KWhiteColor;
        _bankNameLabel.font = SYSTEMFONT(kRealwidth(17));
        _bankNameLabel.textAlignment = NSTextAlignmentLeft;
        _bankNameLabel;
    })];
    [_bankNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_bankNameTipsLabel.mas_right).offset(kRealwidth(35));
        make.top.mas_equalTo(_bankNameTipsLabel.mas_top);
        make.right.mas_equalTo(_infoContentView.mas_right).offset(kRealwidth(30));
        make.height.mas_equalTo(kRealwidth(17));
    }];
    
    [_infoContentView addSubview:({
        _cardNumberLabel = [[UILabel alloc] init];
        _cardNumberLabel.text = @"";
        _cardNumberLabel.textColor = KWhiteColor;
        _cardNumberLabel.font = SYSTEMFONT(kRealwidth(17));
        _cardNumberLabel.textAlignment = NSTextAlignmentLeft;
        _cardNumberLabel;
    })];
    [_cardNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_cardNumberTipsLabel.mas_right).offset(kRealwidth(35));
        make.top.mas_equalTo(_cardNumberTipsLabel.mas_top);
        make.right.mas_equalTo(_infoContentView.mas_right).offset(kRealwidth(30));
        make.height.mas_equalTo(kRealwidth(17));
    }];
}

- (void)setBankModel:(WHBankModel *)bankModel {
    _bankModel = bankModel;
    
    NSString *totalName = [WHBankNameHelper returnBankName:bankModel.bankNumber];
    NSArray *totalArray = [totalName componentsSeparatedByString:@"·"];
    NSString *bankName = [totalArray firstObject];
    NSString *subName = [totalArray lastObject];
    _bankDesLabel.text = NSStringFormat(@"%@(%@)", bankName, subName);
    
//    _bankDesLabel.text = bankModel.bankName;
    _userNameLabel.text = bankModel.cardName;
    _bankNameLabel.text = bankModel.openingBank;
    
    NSString *lastNumber = [bankModel.bankNumber substringWithRange:NSMakeRange(bankModel.bankNumber.length - 4, 4)];
    NSString *cardDes = NSStringFormat(@"**** **** **** %@", lastNumber);
    _cardNumberLabel.text = cardDes;
}

@end
